<%@ page import="eneity.User" %><%--
  Created by IntelliJ IDEA.
  User: MSI-CN
  Date: 2021/1/24
  Time: 0:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); %>
<% if (session.getAttribute("username")==null){
    response.sendRedirect("index.jsp");
}%>
<html>
<head>
    <title>管理员页面</title>
    <style>
        #listBox table{
            margin: 0 auto;
        }
        #addTopicBox{

        }
        .text-center{
            width: 300px;
        }
        .btn-toolbar{
            text-align: center;
        }
        .btn-group{
            margin: 0 auto;
        }
        #titlebox > .row >div{
            height: 50px;
        }
    </style>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
</head>
<%
    boolean result= (boolean) session.getAttribute("isLogin");
    if (!result){
        response.sendRedirect("index.jsp");
    }
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<body>
<div class="container-fluid" id="titlebox">
    <div class="row">
        <div class="col-3">
            <form class="form-inline mb-2" action="<%=path%>/logout" method="post">
                <div class="form-group mx-sm-3 mb-2">
                    <input type="text" readonly class="form-control-plaintext" id="staticEmail2" value="欢迎您：${username}">
                </div>
                <button type="submit" class="btn btn-primary mb-2">退出</button>
            </form>
        </div>
        <div class="col-3 " style="text-align: right;">
            <button type="button" class="btn btn-outline-primary"  id="addNews" data-toggle="modal"  data-target="#myModalNews">添加新闻</button>
        </div>
        <div class="col-6">
            <form action="<%=path%>/addTypeServlet" id="addTypeServlet">
                <div class="container">
                    <div class="row">
                        <div class="form-group row col-9">
                            <div class="col-6">
                                <div class="row">
                                    <div class="col-6 col-form-label">
                                        <p>查看主题：</p>
                                    </div>
                                    <div class="form-group col-6" style=" ">
                                        <select class="form-control col-12" id="exampleFormControlSelect11121">
                                            <c:forEach items="${topiclist}" var="item">
                                                <option id="${item.tid}">${item.typaName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <label for="inputText" class="col-3 col-form-label">添加主题</label>
                            <div class="col-3">
                                <input type="text" class="form-control" name="topic" id="inputText">
                            </div>
                        </div>
                        <div class="form-group row col-3 text-left" >
                            <div class="col-sm-10">
                                <button type="button" id="inputTextBtn" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="listBox" class="">
    <table class="table table-hover">
        <thead>
        <tr>
            <th scope="col">主题</th>
            <th scope="col">标题</th>
            <th scope="col">发布时间</th>
            <th scope="col">作者</th>
            <th scope="col" class="text-center">概述</th>
            <th scope="col">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="item">
            <tr>
                <td class="tname">${item.tname}</td>
                <td class="ntitle">${item.ntitle}</td>
                <td class="ncreatdate">${item.ncreatdate}</td>
                <td class="nauthor">${item.nauthor}</td>
                <td class="text-center nssmmary">${item.nssmmary}</td>
                <td class="ncontent" style="display: none">${item.ncontent}</td>
                <td class="nid" style="display: none"> ${item.nid}</td>
                <td class=""><button class="myModalBtn btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">编辑</button></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <form action="<%=path%>/topicInfoServlet" class="" id="pageindexForm" method="post">
        <div class="btn-toolbar"  role="toolbar" aria-label="Toolbar with button groups">
                <div class="btn-group  col-2 " role="group" aria-label="First group">
                    <button type="button" class="pagebtn btn btn-secondary">1</button>
                    <button type="button" class="pagebtn btn btn-secondary">2</button>
                    <button type="button" class="pagebtn btn btn-secondary">3</button>
                    <button type="button" class="pagebtn btn btn-secondary">4</button>
                    <button type="button" class="pagebtn btn btn-secondary">5</button>
                    <button type="button" class="pagebtn btn btn-secondary">6</button>
                    <button type="button" class="pagebtn btn btn-secondary">7</button>
                    <button type="button" class="pagebtn btn btn-secondary">8</button>
                </div>
                <input style="display: none" id="pageindex" name="pageindex" value=""   >
                <input style="display: none" id="currenPage" name="currenPage" value=""  >
        </div>
    </form>
</div>
<br>
<br>
<br>

<form action="<%=path%>/newsdetail" style="display: none" id="detailnewsform" method="post">
    <input type="text" style="display: none" name="newsID" id="detailnewsInput">
</form>
<!-- 模态框1（Modal） -->
<div class="modal fade " id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
            </div>
            <div class="modal-body">
                <form action="<%=path%>/editNewsServlet" method="post">
                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="inputPassword4">标题</label>
                            <input type="text" class="form-control" name="title" id="inputPassword4" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="inputEmail5">发布时间</label>
                            <input type="text" class="form-control" name="date" id="inputEmail5" placeholder="发布时间">
                        </div>
                        <div class="form-group col-md-6">
                            <label for="inputPassword6">作者</label>
                            <input type="text" class="form-control" name="author" id="inputPassword6" placeholder="作者">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="exampleFormControlSelect111">板块</label>
                        <select class="form-control" id="exampleFormControlSelect111">
                            <c:forEach items="${topiclist}" var="item">
                                <option id="${item.tid}">${item.typaName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="exampleFormControlInput1">概述</label>
                        <input type="text" class="form-control" name="summany" id="exampleFormControlInput1" placeholder="">
                    </div>
                    <div class="form-group">
                        <label for="exampleFormControlTextarea1">正文</label>
                        <textarea class="form-control" name="mainText" id="exampleFormControlTextarea1" rows="3"></textarea>
                    </div>
                    <input type="text" style="display: none"  id="selectID" name="selectID">
                    <input type="text" style="display: none" value="" id="nID" name="nid">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="submit" class="btn btn-primary">
                            提交更改
                        </button>
                    </div>
                </form>
            </div>

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<%--模态框2--%>
<div class="modal fade " id="myModalNews" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
            </div>
            <div class="modal-body">
                <form  enctype="multipart/form-data" action="<%=path%>/addnews" method="post">
                    <div class="form-row">
                        <div class="form-group col-md-12">
                            <label for="inputPassword4">标题</label>
                            <input type="text" class="form-control" name="title" id="title" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="inputEmail5">发布时间</label>
                            <input type="text" class="form-control" name="date" id="creatTime" placeholder="发布时间">
                        </div>
                        <div class="form-group col-md-6">
                            <label for="inputPassword6">作者</label>
                            <input type="text" class="form-control" name="author" id="author" placeholder="作者">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="topic">板块</label>
                        <select class="form-control" id="topic">
                            <c:forEach items="${topiclist}" var="item">
                                <option id="${item.tid}">${item.typaName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="exampleFormControlInput1">概述</label>
                        <input type="text" class="form-control" name="summany" id="summany" placeholder="">
                    </div>
                    <div class="form-group">
                        <label for="content">正文</label>
                        <textarea class="form-control" name="mainText" id="content" rows="3"></textarea>
                    </div>
                    <input type="text" style="display: none"  id="topicSelectID" name="selectID">
                    <input type="text" style="display: none" value="" id="NewsID" name="nid">
                    <div class="modal-footer">
                        <input type="file" class="form-control-file" id="" name="file">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                        </button>
                        <button type="submit" class="btn btn-primary">
                            提交
                        </button>
                    </div>
                </form>
            </div>

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
<script>
    let topic;
    let title;
    let creatdate;
    let author;
    let summay;
    let maintext;
    let selectID;
    $("#exampleFormControlSelect111").change(function () {
        selectID=$("#exampleFormControlSelect111 option:selected").attr('id');
        $("#selectID").val(selectID);
    });
    $("#topic").change(function () {
        selectID=$("#topic option:selected").attr('id');
        $("#topicSelectID").val(selectID);;
    });
    //load
    $(function () {
        let num=(${currenPage});
        console.log(num)
        $(".pagebtn:eq(${currenPage})").css("background","#5A6268");
    })
    //编辑事件
    $(".myModalBtn").click(
        function (){
            selectID=$("#exampleFormControlSelect111 option:selected ").attr('id');
            topic=$(this).parent().parent().children(".tname").text();
            title=$(this).parent().parent().children(".ntitle").text();
            creatdate=$(this).parent().parent().children(".ncreatdate").text();
            author=$(this).parent().parent().children(".nauthor").text();
            summay=$(this).parent().parent().children(".nssmmary").text();
            maintext=    $(this).parent().parent().children(".ncontent").text();
            $("#inputPassword4").val(title);
            $("#inputEmail5").val(creatdate);
            $("#inputPassword6").val(author);
            $("#exampleFormControlSelect111").val(topic);
            $("#exampleFormControlInput1").val(summay);
            $("#exampleFormControlTextarea1").val(maintext);
            $("#selectID").val($("#exampleFormControlSelect111 option:selected ").attr('id'));
            $("#nID").val($(this).parent().parent().children(".nid").text());
        }
    );
    //tr悬浮
    $(".ntitle").hover(function () {
       $(this).css("cursor","pointer");
    }
    );
    $(".ntitle").click(function () {
       $("#detailnewsInput").val(parseInt($(this).parent().children(".nid").text()));
       let form=$("#detailnewsform");
       form.submit();
    });
    //添加主题事件
    $("#inputTextBtn").click(function () {
        if ($("#inputText").val().length!=0){
            let form=$("#addTypeServlet");
            form.submit();
        }
    });
    //翻页事件
    $(".btn-secondary").click(function () {
        let num1=10;

        let num2= parseInt($(this).text());

        let num3=(num2-1)*num1;

        $("#pageindex").val(num3);
        $("#currenPage").val(num2);
        let form=$("#pageindexForm");
        form.submit();
    });
</script>
</body>
</html>
